package indi.jp.project.core.util;

import indi.jp.project.core.entity.BaseEntity;

import javax.servlet.http.HttpServletRequest;

public class SimpleEntityUtil<T extends BaseEntity> {

    public T setBaseEntity(T entity, HttpServletRequest request) {
        String account = request.getParameter("account");
        entity.setLander(account);
        if(entity.getCreateBy() == null || "".equals(entity.getCreateBy())){
            entity.setCreateBy(account);
        }
        if(entity.getModifyBy() == null || "".equals(entity.getModifyBy())){
            entity.setModifyBy(account);
        }
        int page = entity.getPage();
        int pageSize = entity.getPageSize();

        if (page != 0 && pageSize != 0) {
            int offset = (page - 1) * pageSize;
            entity.setOffset(offset);
        }

        return entity;
    }

}
